// 展示隐藏效果
function shuplod() {
    var status = $(".shuplod").css('display');
    if (status == "none") {
        $(".shuplod").show();
        var boxId = "#shuplod";
        toBox(boxId);
    } else {
        $(".shuplod").hide();
    }
}

function findMtLists($scope, CertusFormAjax) {
    CertusFormAjax.ajax('meetTypeList',{},function (response) {
        $scope.typeList = response.data;
    });

    this.getList = function () {
        CertusFormAjax.ajax('meetingLists',{},function (response) {
            var data = response.data;
            // 会议室预定记录
            var meetColumns = [{
                id: 'mtName',
                title: '会议主题',
                type: 'string',
                width: 150,
                columnClass: 'text-center',
            }, {
                id: 'm3',
                title: '会议开始时间',
                type: 'string',
                width: 170,
                columnClass: 'text-center',
                resolution: function (value, record) {
                    var content = '';
                    content += record.beginTime+' '+record.start;
                    return content;
                }
            }, {
                id: 'm4',
                title: '会议结束时间',
                type: 'string',
                width: 170,
                columnClass: 'text-center',
                resolution: function (value, record) {
                    var content = '';
                    content += record.endTime+' '+record.end;
                    return content;
                }
            }, {
                id: 'createUser',
                title: '预订人',
                type: 'string',
                width: 75,
                columnClass: 'text-center',
            }, {
                id: 'opinions',
                title: '意见留言',
                type: 'string',
                columnClass: 'text-left',
            }, {
                id: 'operation',
                title: '操作',
                width: 150,
                type: 'string',
                columnClass: 'text-center',
                resolution: function (value, record) {
                    var content = '';
                    content += '<a class="btn btn-xs btn-primary" href="#/selMeeting/'+record.id+'"><i class="icon-eye-open"> 查看</i></a>';
                    if (record.createUserId==data.createUser){
                        content += '  ';
                        content += '<a class="btn btn-xs btn-success" onclick="del(\''+record.id+'\');"><i class="icon-ok"></i>  取消预定</a>';
                    }
                    return content;
                }
            }];
            $("#meetContainer").empty();
            $("#meetToolBarContainer").empty();

            var meetOption = {
                lang: 'zh-cn',
                ajaxLoad: false,
                // loadURL:'url',
                exportFileName: '会议室预定列表',
                datas: data.meetList,
                columns: meetColumns,
                gridContainer: 'meetContainer',
                toolbarContainer: 'meetToolBarContainer',
                tools: '',
                extraWidth: 20,
                pageSize: 10,
                pageSizeLimit: [10, 15, 20]
            };
            var meetGrid = $.fn.dlshouwen.grid.init(meetOption);
            meetGrid.load();
        });
    };
    getList();
    //会议室视图列表
    // 表格渲染效果js
    var arrs={};
    this.stList = function () {
        CertusFormAjax.ajax('findStlist',{},function (response) {
            var data = response.data;
            //封装视图列表数据
            var meeting=[];
            for (var i=0;i<data.length;i++){
                var arr_1={};
                var arr_2={};
                var users={};
                arr_1.meetType = data[i].type_id;
                arr_2.meetName = data[i].meeting_name;
                arr_2.meetTitle = data[i].mt_name;
                arr_2.startTime = data[i].time1+" "+data[i].start;
                arr_2.endTime = data[i].time2+" "+data[i].end;
                arr_2.meetNo = data[i].meeting_no;
                arr_1.meet = arr_2;
                users.userName = data[i].create_user;
                users.dep = data[i].dept_names;
                users.meetTell = data[i].phone_number2;
                users.meetEmail = data[i].email;
                arr_1.users = users;
                meeting.push(arr_1);
            }
            arrs.meeting = meeting;
            Meeting("#meetlist", 0, "", arrs);
        });
    };

    stList();
    this.sub = function () {
        var type = $("#type option:selected").val();
        var inTime = $("#inTime").val();
        Meeting("#meetlist", type, inTime,arrs);
    };

    this.del = function (id) {
        layer.confirm('确认取消预定？', {
            btn: ['确认', '取消'] //按钮
        }, function () {
            CertusFormAjax.ajax('delList',{"id":id},function () {
                this.getList();
                this.stList();
                layer.msg('执行成功！', {
                    icon: 1
                });
            });
        });
    }
}

function findMts($scope, CertusFormAjax, $routeParams) {
    CertusFormAjax.ajax('meetTypeList',{},function (response) {
        $scope.typeList = response.data;
    });

    CertusFormAjax.ajax('findById',{"id":$routeParams.id},function (response) {
        var data = response.data;
        $scope.typeId = data.typeId+"";
        $scope.mtName = data.mtName;
        $scope.peopleNum = data.peopleNum;
        $scope.beginTime = data.beginTime;
        $scope.start = data.start;
        $scope.endTime = data.endTime;
        $scope.end = data.end;
        $scope.comments = data.comments;
        $scope.opinions = data.opinions;

        var translateArr = data.translate.split(",");
        for (var i=0;i<translateArr.length;i++){
            if (translateArr[i]!=""){
                $("#translate").find("input[type='checkbox']").each(function (k,n) {
                    if ($(n).val()==translateArr[i]){
                        $(n).attr("checked","checked");
                    }
                });
            }
        }
    });
}